/********************************************
* Copyrigt (C) rumi
* Module: mgr_tracedata.h
*********************************************/
#ifndef mgr_tracedata_H
#define mgr_tracedata_H

#include <iomanip> 
#include <sstream>
#include <semaphore.h>

#define SHM_NAME_RECV "auto_netshm_recv"
#define SHM_NAME_SEND "auto_netshm_send"

typedef struct
{
    uint8_t Stand;
    uint8_t forward;
    uint8_t back;
    uint8_t Left;
    uint8_t Right;
}Trace_Control_typedef;

typedef struct
{
    uint8_t SoftWareVer;
    uint8_t SoftWareBuildVer;
    uint8_t HardWareVer;
    uint8_t BootLoaderVer;
}Trace_Ver_typedef;

typedef struct 
{
	int32_t U_kk;    	    // The amount of the last output
	int32_t ekk;		 	// The last input deviation
	int32_t ekkk;			// The input deviation of the previous time
	int32_t Ur;				// The limiting output value needs to be initialized
	int32_t Kp;				// scale
	int32_t Ki;				// integration
	int32_t Kd;				// differential
	
	uint8_t En;             // switch
	int16_t Adjust;         // Adjust the amount
	int16_t ValSet;       	// Speed settings
	int16_t ValNow;       	// Current speed

}Trace_PID_typedef;


typedef struct
{
    uint8_t foreward;
    uint8_t back;
    uint8_t left;
    uint8_t right;
    uint8_t ReadVer;

}Trace_CtrlSned_typedef;

typedef struct
{
    int32_t Kp;				// scale
	int32_t Ki;				// integration
	int32_t Kd;				// differential

}Trace_PIDSned_typedef;

typedef struct
{
    Trace_CtrlSned_typedef   Ctrl;
    Trace_PIDSned_typedef    Pid_Left;
    Trace_PIDSned_typedef    Pid_Right;
    Trace_PIDSned_typedef    Pid_Stand;
    Trace_PIDSned_typedef    Pid_Ster;

}Trace_SendData_Typedef;

typedef struct
{
    Trace_Ver_typedef       Ver;
    Trace_PID_typedef       Pid_Left;
    Trace_PID_typedef       Pid_Right;
    Trace_PID_typedef       Pid_Stand;
    Trace_PID_typedef       Pid_Ster;
    Trace_Control_typedef   Move;

}Trace_RecvData_Typedef;

enum DataState {
    DataState_Idle,
    DataState_Working,  
};

typedef enum
{
	E_CMD_HANDSHAKE      = 0x01, 
    E_CMD_READVER        = 0x02,
    E_CMD_HEARTBEAT      = 0x03,
    
    E_CMD_DIAG           = 0x0D,
    E_CMD_ERROR          = 0x0E,
    E_CMD_IFC            = 0x0F,

    E_CMD_PID_LEFT       = 0x10,
    E_CMD_PID_RIGHT,
    E_CMD_PID_STAND,
    E_CMD_PID_STER,
    E_CMD_MOVE,

    E_CMD_MAX,

}TRACE_CMD_ENUM;

typedef struct{
    sem_t Sem_Notice;          
    uint8_t DataState;         
    TRACE_CMD_ENUM DataType;   
    Trace_RecvData_Typedef Data;  
}SharedMemory_Recv_TypeDef;


typedef struct{
    sem_t Sem_Notice;          
    uint8_t DataState;         
    TRACE_CMD_ENUM DataType;   
    Trace_SendData_Typedef Data;  
}SharedMemory_Send_TypeDef;

#endif
/********************************************
 * End of file
*********************************************/